﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d01_tjxxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d01_tjxx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d01_tjxxMgr mgr = new d01_tjxxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d01_tjxx(e.Parameters[d01_tjxx_Filter.ParamPrefix]));
            IList<d01_tjxx> list = mgr.FindAllByPage_d01_tjxx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d01_tjxx_Filter.ParamPrefix]);
            d01_tjxx_MainStore.DataSource = list;
            d01_tjxx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d01_tjxxMgr mgr = new d01_tjxxMgr();
            RowSelectionModel sm = d01_tjxx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d01_tjxx _d01_tjxx = new d01_tjxx();
                _d01_tjxx.grbm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d01_tjxx(_d01_tjxx))
                {
                    log.Debug("d01_tjxx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d01_tjxx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d01_tjxxMgr mgr = new d01_tjxxMgr();
            d01_tjxx _d01_tjxx = new d01_tjxx();
            if (Hid.Text.Length > 0)
                _d01_tjxx = mgr.FindById_d01_tjxx(int.Parse(Hid.Text));
            
			_d01_tjxx.dzbm = Txtdzbm.Text.Trim();
			_d01_tjxx.hbh = Txthbh.Text.Trim();
			_d01_tjxx.brxm = Txtbrxm.Text.Trim();
			_d01_tjxx.sfzh = Txtsfzh.Text.Trim();
			_d01_tjxx.ylzh = Txtylzh.Text.Trim();
			_d01_tjxx.brxb = Txtbrxb.Text.Trim();
			_d01_tjxx.brnl = Txtbrnl.Text.Trim();
			_d01_tjxx.csrq = Txtcsrq.Text.Trim();
			_d01_tjxx.hyzk = Txthyzk.Text.Trim();
			_d01_tjxx.mz = Txtmz.Text.Trim();
			_d01_tjxx.csd = Txtcsd.Text.Trim();
			_d01_tjxx.szdq = Txtszdq.Text.Trim();
			_d01_tjxx.jkzk = Txtjkzk.Text.Trim();
			_d01_tjxx.gzdw = Txtgzdw.Text.Trim();
			_d01_tjxx.zy = Txtzy.Text.Trim();
			_d01_tjxx.chsj = Txtchsj.Text.Trim();
			_d01_tjxx.mzyl = Txtmzyl.Text.Trim();
			_d01_tjxx.zzbm = Txtzzbm.Text.Trim();
			_d01_tjxx.zycs = Txtzycs.Text.Trim();
			_d01_tjxx.mblx1 = Txtmblx1.Text.Trim();
			_d01_tjxx.mblx2 = Txtmblx2.Text.Trim();
			_d01_tjxx.grs = Txtgrs.Text.Trim();
			_d01_tjxx.dqzt = Txtdqzt.Text.Trim();
			_d01_tjxx.rcbz = Txtrcbz.Text.Trim();
			_d01_tjxx.rcsj = Txtrcsj.Text.Trim();
			_d01_tjxx.rqyy = Txtrqyy.Text.Trim();
			_d01_tjxx.sj = Txtsj.Text.Trim();
			_d01_tjxx.whcd = Txtwhcd.Text.Trim();
			_d01_tjxx.ear = Txtear.Text.Trim();
			_d01_tjxx.earleft = Txtearleft.Text.Trim();
			_d01_tjxx.earright = Txtearright.Text.Trim();
			_d01_tjxx.nk = Txtnk.Text.Trim();
			_d01_tjxx.xy = Txtxy.Text.Trim();
			_d01_tjxx.wk = Txtwk.Text.Trim();
			_d01_tjxx.sg = Txtsg.Text.Trim();
			_d01_tjxx.tz = Txttz.Text.Trim();
			_d01_tjxx.xt = Txtxt.Text.Trim();
			_d01_tjxx.epk = Txtepk.Text.Trim();
			_d01_tjxx.kqk = Txtkqk.Text.Trim();
			_d01_tjxx.xbts = Txtxbts.Text.Trim();
			_d01_tjxx.bc = Txtbc.Text.Trim();
			_d01_tjxx.xdt = Txtxdt.Text.Trim();
			_d01_tjxx.xs = Txtxs.Text.Trim();
			_d01_tjxx.xh = Txtxh.Text.Trim();
			_d01_tjxx.qt = Txtqt.Text.Trim();
			_d01_tjxx.jl = Txtjl.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d01_tjxx(_d01_tjxx);
            else
                isok = mgr.Add_d01_tjxx(_d01_tjxx);
            if (isok)
            {
                d01_tjxx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d01_tjxx中执行了保存（插入或修改），并成功");
                d01_tjxx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}